#!/bin/bash
set -ex

# 更新 PEAR 和 PECL 通道
pear upgrade --force PEAR || true
pecl channel-update pecl.php.net

# 安装系统依赖
apt-get update && apt-get install -y \
    git zip unzip libicu-dev libzip-dev libonig-dev libxml2-dev \
    libssl-dev libpng-dev libjpeg-dev libfreetype6-dev libwebp-dev \
    libcurl4-openssl-dev libsqlite3-dev libxslt-dev zlib1g-dev \
    libaio-dev libpcre3-dev pkg-config re2c bison autoconf \
    && rm -rf /var/lib/apt/lists/*

# 配置并安装内置扩展（gd 启用 freetype/jpeg/webp）
docker-php-ext-configure gd \
    --with-freetype \
    --with-jpeg \
    --with-webp

docker-php-ext-install bcmath curl ftp gd gettext intl mbstring \
    mysqli pdo pdo_mysql pdo_sqlite pcntl shmop sockets sysvsem

# PECL 扩展安装
yes '' | pecl install mongodb
yes '' | pecl install msgpack
yes '' | pecl install redis
yes '' | pecl install swoole

# 启用扩展
docker-php-ext-enable mongodb msgpack redis swoole


# 清理 PHP 扩展构建过程中产生的中间文件（不影响运行时）
find /usr/src/php/ext -name '*.gcno' -o -name '*.gcda' -o -name '*.lo' -o -name '*.o' -o -name '*.la' | xargs rm -f || true
find /usr/src/php/ext -name .libs -type d | xargs rm -rf || true






